3 * Include most things that's need to customize the site
8 * This file is not a valid entry point, perform no further processing unless
11 if( defined( 'MEDIAWIKI' ) ) {
13 # The main wiki script and things like database
14 # conversion and maintenance scripts all share a
15 # common setup of including lots of classes and
16 # setting up a few globals.
19 // Check to see if we are at the file scope
20 if ( !isset( $wgVersion ) ) {
21 die( "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n" );
24 if( !isset( $wgProfiling ) )
27 if ( $wgProfiling and (0 == rand() %
$wgProfileSampleRate ) ) {
28 require_once( 'Profiling.php' );
29 if ($wgProfilerType == "") {
30 $wgProfiler = new Profiler();
32 $prclass="Profiler{$wgProfilerType}";
33 require_once( $prclass.".php" );
34 $wgProfiler = new $prclass();
37 function wfProfileIn( $fn = '' ) {
38 global $hackwhere, $wgDBname;
40 if (function_exists("setproctitle"))
41 setproctitle($fn . " [$wgDBname]");
43 function wfProfileOut( $fn = '' ) {
44 global $hackwhere, $wgDBname;
45 if (count($hackwhere))
46 array_pop($hackwhere);
47 if (function_exists("setproctitle") && count($hackwhere))
48 setproctitle($hackwhere[count($hackwhere)-1] . " [$wgDBname]");
50 function wfGetProfilingOutput( $s, $e ) {}
51 function wfProfileClose() {}
52 function wfLogProfilingData() {}
56 wfProfileIn( $fname );
57 wfProfileIn( $fname.'-includes' );
59 require_once( 'GlobalFunctions.php' );
60 require_once( 'Hooks.php' );
61 require_once( 'Namespace.php' );
62 require_once( 'RecentChange.php' );
63 require_once( 'User.php' );
64 require_once( 'Skin.php' );
65 require_once( 'OutputPage.php' );
66 require_once( 'LinkCache.php' );
67 require_once( 'Title.php' );
68 require_once( 'Article.php' );
69 require_once( 'MagicWord.php' );
70 require_once( 'Block.php' );
71 require_once( 'MessageCache.php' );
72 require_once( 'Parser.php' );
73 require_once( 'ParserCache.php' );
74 require_once( 'WebRequest.php' );
75 require_once( 'LoadBalancer.php' );
76 require_once( 'HistoryBlob.php' );
77 require_once( 'ProxyTools.php' );
78 require_once( 'ObjectCache.php' );
79 require_once( 'WikiError.php' );
80 require_once( 'SpecialPage.php' );
82 if ( $wgUseDynamicDates ) {
83 require_once( 'DateFormatter.php' );
86 wfProfileOut( $fname.'-includes' );
87 wfProfileIn( $fname.'-misc1' );
89 $wgIP = false; # Load on demand
90 $wgRequest = new WebRequest();
91 $wguname = @posix_uname
();
94 if ( $wgCommandLineMode ) {
95 # wfDebug( '"' . implode( '" "', $argv ) . '"' );
96 } elseif ( function_exists( 'getallheaders' ) ) {
97 wfDebug( "\n\nStart request\n" );
98 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
99 $headers = getallheaders();
100 foreach ($headers as $name => $value) {
101 wfDebug( "$name: $value\n" );
104 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
105 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
109 $wgSkipSkins[] = $wgSkipSkin;
112 $wgUseEnotif = $wgEnotifUserTalk ||
$wgEnotifWatchlist;
114 wfProfileOut( $fname.'-misc1' );
115 wfProfileIn( $fname.'-memcached' );
117 $wgMemc =& wfGetMainCache();
118 $messageMemc =& wfGetMessageCacheStorage();
119 $parserMemc =& wfGetParserCacheStorage();
121 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
122 "\nMessage cache: " . get_class( $messageMemc ) .
123 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
125 wfProfileOut( $fname.'-memcached' );
126 wfProfileIn( $fname.'-SetupSession' );
129 session_name( $wgDBname . '_' . $wgDBprefix . '_session' );
131 session_name( $wgDBname . '_session' );
134 if( !$wgCommandLineMode && ( isset( $_COOKIE[session_name()] ) ||
isset( $_COOKIE[$wgDBname.'Token'] ) ) ) {
135 wfIncrStats( 'request_with_session' );
136 User
::SetupSession();
137 $wgSessionStarted = true;
139 wfIncrStats( 'request_without_session' );
140 $wgSessionStarted = false;
143 wfProfileOut( $fname.'-SetupSession' );
144 wfProfileIn( $fname.'-database' );
146 if ( !$wgDBservers ) {
147 $wgDBservers = array(array(
148 'host' => $wgDBserver,
150 'password' => $wgDBpassword,
151 'dbname' => $wgDBname,
154 'flags' => ($wgDebugDumpSql ? DBO_DEBUG
: 0) | DBO_DEFAULT
157 $wgLoadBalancer = LoadBalancer
::newFromParams( $wgDBservers, false, $wgMasterWaitTimeout );
158 $wgLoadBalancer->loadMasterPos();
160 wfProfileOut( $fname.'-database' );
161 wfProfileIn( $fname.'-language1' );
163 require_once( "$IP/languages/Language.php" );
165 function setupLangObj($langclass) {
168 if( ! class_exists( $langclass ) ) {
169 # Default to English/UTF-8
170 $baseclass = 'LanguageUtf8';
171 require_once( "$IP/languages/$baseclass.php" );
172 $lc = strtolower(substr($langclass, 8));
174 class $langclass extends $baseclass {
175 function getVariants() {
176 return array(\"$lc\");
183 $lang = new $langclass();
188 # $wgLanguageCode may be changed later to fit with user preference.
189 # The content language will remain fixed as per the configuration,
191 $wgContLanguageCode = $wgLanguageCode;
192 $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
194 $wgContLang = setupLangObj( $wgContLangClass );
195 $wgContLang->initEncoding();
197 wfProfileOut( $fname.'-language1' );
198 wfProfileIn( $fname.'-User' );
200 # Skin setup functions
201 # Entries can be added to this variable during the inclusion
202 # of the extension file. Skins can then perform any necessary initialisation.
203 foreach ( $wgSkinExtensionFunctions as $func ) {
204 require_once 'PersistentObject.php';
206 call_user_func( $func );
209 if( !is_object( $wgAuth ) ) {
210 require_once( 'AuthPlugin.php' );
211 $wgAuth = new AuthPlugin();
214 if( $wgCommandLineMode ) {
215 # Used for some maintenance scripts; user session cookies can screw things up
216 # when the database is in an in-between state.
217 $wgUser = new User();
218 # Prevent loading User settings from the DB.
219 $wgUser->setLoaded( true );
222 wfRunHooks('AutoAuthenticate',array(&$wgUser));
223 if ($wgUser === null) {
224 $wgUser = User
::loadFromSession();
228 wfProfileOut( $fname.'-User' );
229 wfProfileIn( $fname.'-language2' );
231 // wgLanguageCode now specifically means the UI language
232 $wgLanguageCode = $wgRequest->getText('uselang', '');
233 if ($wgLanguageCode == '')
234 $wgLanguageCode = $wgUser->getOption('language');
235 # Validate $wgLanguageCode, which will soon be sent to an eval()
236 if( empty( $wgLanguageCode ) ||
!preg_match( '/^[a-z]+(-[a-z]+)?$/', $wgLanguageCode ) ) {
237 $wgLanguageCode = $wgContLanguageCode;
240 $wgLangClass = 'Language'. str_replace( '-', '_', ucfirst( $wgLanguageCode ) );
242 if( $wgLangClass == $wgContLangClass ) {
243 $wgLang = &$wgContLang;
245 wfSuppressWarnings();
246 include_once("$IP/languages/$wgLangClass.php");
249 $wgLang = setupLangObj( $wgLangClass );
252 wfProfileOut( $fname.'-language2' );
253 wfProfileIn( $fname.'-MessageCache' );
255 $wgMessageCache = new MessageCache
;
256 $wgMessageCache->initialise( $parserMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname);
258 wfProfileOut( $fname.'-MessageCache' );
261 # I guess the warning about UI switching might still apply...
263 # FIXME: THE ABOVE MIGHT BREAK NAMESPACES, VARIABLES,
264 # SEARCH INDEX UPDATES, AND MANY MANY THINGS.
265 # DO NOT USE THIS MODE EXCEPT FOR TESTING RIGHT NOW.
267 # To disable it, the easiest thing could be to uncomment the
268 # following; they should effectively disable the UI switch functionality
270 # $wgLangClass = $wgContLangClass;
271 # $wgLanguageCode = $wgContLanguageCode;
272 # $wgLang = $wgContLang;
274 # TODO: Need to change reference to $wgLang to $wgContLang at proper
275 # places, including namespaces, dates in signatures, magic words,
278 # TODO: Need to look at the issue of input/output encoding
282 wfProfileIn( $fname.'-OutputPage' );
284 $wgOut = new OutputPage();
286 wfProfileOut( $fname.'-OutputPage' );
287 wfProfileIn( $fname.'-misc2' );
289 $wgDeferredUpdateList = array();
290 $wgPostCommitUpdateList = array();
292 $wgLinkCache = new LinkCache();
293 $wgMagicWords = array();
294 $wgMwRedir =& MagicWord
::get( MAG_REDIRECT
);
295 $wgParserCache = new ParserCache( $messageMemc );
297 if ( $wgUseXMLparser ) {
298 require_once( 'ParserXML.php' );
299 $wgParser = new ParserXML();
301 $wgParser = new Parser();
303 $wgOut->setParserOptions( ParserOptions
::newFromUser( $wgUser ) );
304 $wgMsgParserOptions = ParserOptions
::newFromUser($wgUser);
307 # Placeholders in case of DB error
308 $wgTitle = Title
::makeTitle( NS_SPECIAL
, 'Error' );
309 $wgArticle = new Article($wgTitle);
311 wfProfileOut( $fname.'-misc2' );
312 wfProfileIn( $fname.'-extensions' );
314 # Extension setup functions for extensions other than skins
315 # Entries should be added to this variable during the inclusion
316 # of the extension file. This allows the extension to perform
317 # any necessary initialisation in the fully initialised environment
318 foreach ( $wgExtensionFunctions as $func ) {
319 require_once 'PersistentObject.php';
321 call_user_func( $func );
325 $wgFullyInitialised = true;
326 wfProfileOut( $fname.'-extensions' );
327 wfProfileOut( $fname );